<?
 if ($_SERVER['REQUEST_METHOD']=="POST"){

	// send message where?
	$to="email@example.com";
	
	$subject="subPages Story Submission from $email";

	// sender name and email -- if name exists.  it doesnt right now but i will add it in soon
	$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['email']).">";

	$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

	// form variables
	$tmp_name = $_FILES['filename']['tmp_name'];
	$type = $_FILES['filename']['type'];
	$name = $_FILES['filename']['name'];
	$size = $_FILES['filename']['size'];
	$title = $_REQUEST['title'] ;
	$destination = $_REQUEST['destination'] ;
	$story = $_REQUEST['story'] ;
	$email = $_REQUEST['email'];

	// email message
	$message = "Title: $title\nDestination: $destination\nPhoto: $name\nStory: $story\nFrom Email: $email\n";

	// if upload succeded
	if (file_exists($tmp_name)){

	if(is_uploaded_file($tmp_name)){

         $file = fopen($tmp_name,'rb');

         $data = fread($file,filesize($tmp_name));

         fclose($file);

         $data = chunk_split(base64_encode($data));
  }

	// headers
	$headers = "From: $from\r\n" .
         "MIME-Version: 1.0\r\n" .
         "Content-Type: multipart/mixed;\r\n" .
         " boundary=\"{$mime_boundary}\"";

      // body message format
      $message = "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";

      // start attachment
      $message .= "--{$mime_boundary}\n" .
         "Content-Type: {$type};\n" .
         " name=\"{$name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

      // now please work... pretty please :)
      if (@mail($to, $subject, $message, $headers))
         header( "Location: /thanks" );
      else
          header( "Location: /submit" );
   }
}
?>
